<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>登录日志 - 用户管理 - 我的后台</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="__STATIC__/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="__CSS__/news.css" media="all" />
</head>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
		<div class="layui-inline">
			<div class="layui-form">
				<label class="layui-form-label">用户分组</label>
				<div class="layui-input-block">
					<select name="pid" id="search" lay-verify="search" lay-search>
						{volist name="grouplist" id="vo"}
					  		<option value="{$vo.group_id}">{$vo.name}</option>
						{/volist}
					</select>
				</div>
			</div>
		</div>
		<div class="layui-inline">
			<a class="layui-btn" id="search-btn" data-type="reload" href="javascript:;">搜索</a>
		</div>

	</blockquote>
	<div class="layui-form news_list">
		<table class="layui-hide" id="demo" lay-filter="demo"></table>
	</div>

	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs layui-btn-danger" title="删除" lay-event="del">
			<i class="layui-icon">&#xe640;</i>
		</a>
	</script>

	<script type="text/javascript" src="__STATIC__/layui/layui.js"></script>
	<script type="text/javascript">
		
		layui.use(['form', 'layer', 'table'],function(){
			var form  = layui.form,
				layer = layui.layer,
				table = layui.table,
				$ = layui.$;

				layer.msg("加载中...", {'time':1000});

				table.render({
					elem: '#demo'
					,page:true
					,url:'/admin/user/log?type=1'
					,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					,cols: [[
						{field:'login_id', title: 'ID', width:120, sort: true}
						,{field:'username', title: '用户名', width:250}
						,{field:'nickname', title: '昵称', width:250}
						,{field:'group', title: '分组', width:200}
						,{field:'login_ip', title: '登录IP', width: 250}
						,{field:'login_time', title: '登录时间', width: 250, sort: true}
						,{fixed:'right', title: '操作',toolbar:"#barDemo"}
					]]
				});	

		        //搜索
		        var active = {
		            reload: function(){
		                table.reload('demo', {
		                    page: {
		                        curr: 1 //重新从第 1 页开始
		                    },
		                    where: {
		                        group_id: $('#search').val()
		                    }
		                });
		            }
		        };

		        $('.news_search #search-btn').on('click', function(){
		            var type = $(this).data('type');
		            active[type] ? active[type].call(this) : '';
		        });

		        //监听工具条
		        table.on('tool(demo)', function(obj){
		            var data     = obj.data,
		                layEvent = obj.event;
					if(layEvent === 'del'){
		                layer.confirm('确定删除？', function (index) {
		                    //向服务端发送删除指令
		                    var login_id = data.login_id;
		                    $.ajax({
		                        url: "/admin/user/delog",
		                        type: "POST",
		                        data: {"login_id": login_id},
		                        dataType: "json",
		                        success: function (data) {
		                            if (data.status == '1') {
		                                //删除这一行
		                                obj.del();
		                                //关闭弹框
		                                layer.close(index);
		                                layer.msg(data.msg, {icon: 6});
		                            } else {
		                                layer.msg(data.msg, {icon: 5});
		                            }
		                        }
		                    });
		                });
		            }
		        });

		})	
	</script>
</body>
</html>